/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * iForm.java
 *
 * Created on 2009-03-21, 13:55:25
 */
package bt;

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.LayoutManager;
import java.awt.MediaTracker;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.logging.Level;
import javax.bluetooth.RemoteDevice;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.plaf.metal.MetalIconFactory;
import net.sf.bluecove.obex.*;

/**
 *
 * @author kszyh
 */
public class iForm extends javax.swing.JFrame implements UserInteraction {

    private ImageIcon transferIcon;
    private ImageIcon searchIcon;
    private ImageIcon downloadIcon;
    private String fileName;
    private ImageIcon btIcon;
    private String status;
    Vector nazwyKlientow;
    private List queue = new Vector();
    private Hashtable devices = new Hashtable();
    private DeviceInfo InstallDevice;
    private String encodedImage;
    public BTServer bs;

    /** Creates new form iForm */
    public iForm() {
        initLista();
        initComponents();
        initMyComponnents();
        initListaListener();

        //transferIcon = new ImageIcon((Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/transfer.png"))));
        //searchIcon = new ImageIcon((Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/search.png"))));
        //downloadIcon = new ImageIcon((Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/download.png"))));
        //Image btImage = Toolkit.getDefaultToolkit().getImage(Main.class.getResource("/icon.png"));
        //searchIcon =  transferIcon = downloadIcon = (ImageIcon) MetalIconFactory.getTreeFolderIcon();


        btIcon = new ImageIcon();
        transferIcon = searchIcon = downloadIcon = new ImageIcon();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new JList(model);
        jList1.setCellRenderer(new IconListRenderer(icons));
        jScrollPane1 = new javax.swing.JScrollPane();
        jEditorPane1 = new javax.swing.JEditorPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jButton1.setText("Wyślij");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jList1MouseEntered(evt);
            }
        });
        jScrollPane2.setViewportView(jList1);

        jEditorPane1.setContentType("text/html");
        jEditorPane1.setEditable(false);
        jScrollPane1.setViewportView(jEditorPane1);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane3.setViewportView(jTextArea1);

        jButton2.setText("Wyszukaj");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Połącz");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ConnectButton(evt);
            }
        });

        jButton6.setText("Wyślij program");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("jButton7");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jMenu1.setText("Plik");

        jMenuItem1.setText("Wyszukaj urządzenia");
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Wyszukaj klientów");
        jMenu1.add(jMenuItem2);

        jMenuItem4.setText("Ustawienia");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pokazUstawienia(evt);
            }
        });
        jMenu1.add(jMenuItem4);
        jMenu1.add(jSeparator1);

        jMenuItem3.setText("Wyjście");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Wyjscie(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Działania");

        jMenuItem5.setText("Wyślij obrazek");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpenFormImage(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("Pomoc");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 422, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 34, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addGap(59, 59, 59)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /*
     * Implemetuje najazd na pozycję JList
     * Wyswietlanie Adresu Urządzania na pasku StatusBar
     */
    private void initListaListener() {
        jList1.addMouseMotionListener(new MouseAdapter() {

            @Override
            public void mouseMoved(MouseEvent me) {
                try {
                    Point p = new Point(me.getX(), me.getY());
                    int index = jList1.locationToIndex(p);
                    jStatusBar1.setMessage("Adres Bluetooth urządzenia: " + f.getUrlFromIndex(index));
                } catch (Exception e) {
                }
            }
        });

    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        changeB2Name();
        clearList();
        f = new Finder("8b9602b38b854a339ca4b79463ec4949");
        jStatusBar1.setMessage("Wyszukiwanie urządzeń... Proszę czekać.");

    }//GEN-LAST:event_jButton2ActionPerformed

    public void changeB2Name() {
        if ((jButton2.getText().equals("Wyszukaj"))) {
            jButton2.setText("Przerwij");
            jButton2.setIcon(MetalIconFactory.getTreeFloppyDriveIcon());
        } else {
            jButton2.setText("Wyszukaj");
            jButton2.setIcon(MetalIconFactory.getTreeFolderIcon());
        }
    }

    private void Wyjscie(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Wyjscie
        System.exit(0);
    }//GEN-LAST:event_Wyjscie

    private void jList1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_jList1MouseEntered

    private void pokazUstawienia(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pokazUstawienia
        iSettings ust = new iSettings();
        ust.setVisible(true);
        ust.setAlwaysOnTop(true);
        ust.setTitle("Ustawienia");


    }//GEN-LAST:event_pokazUstawienia

    private void ConnectButton(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ConnectButton
        int[] selectedIx = jList1.getSelectedIndices();

        if (selectedIx.length == 0) {
            JOptionPane.showMessageDialog(this, "Musisz wybrać choć jednego klienta", "Błąd", JOptionPane.ERROR_MESSAGE);
            return;
        } else {

            nazwyKlientow = new Vector();
            for (int i = 0; i < selectedIx.length; i++) {
                String name = (String) jList1.getModel().getElementAt(selectedIx[i]);
                nazwyKlientow.addElement(name);
            }

            Vector cele = f.selectS(nazwyKlientow);
            c = new Connector(cele);
            c.makeConnections();
            bs = new BTServer(c.getCons(),false);
        }
    }//GEN-LAST:event_ConnectButton

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        if (fileChooser == null) {
            fileChooser = new JFileChooser();
            fileChooser.setDialogTitle("Select File to send...");
            fileChooser.setCurrentDirectory(new File(Persistence.getProperty("recentDirectory", ".")));
        }
        int returnVal = fileChooser.showOpenDialog(iForm.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            Persistence.setProperty("recentDirectory", fileChooser.getCurrentDirectory().getAbsolutePath());
            downloadFile(DropTransferHandler.getCanonicalFileURL(fileChooser.getSelectedFile()));

        //saveConfig();
        }


    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        int[] selectedIx = jList1.getSelectedIndices();

        if (selectedIx.length != 0) {
            JOptionPane.showMessageDialog(this, "Musisz wybrać jednego klienta", "Błąd", JOptionPane.ERROR_MESSAGE);
            return;
        } else {
            String name = (String) jList1.getModel().getElementAt(selectedIx[0]);
            String url = f.Whois(name);
            obexPrepare(url, name);
            obexSend();
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    public void ImageToBase64(String filepatch) throws FileNotFoundException, IOException {
        byte[] tablica = imageToByteArray(filepatch);
        String b64 = Base64.encode(tablica);
        encodedImage = b64;

    }

    public byte[] imageToByteArray(String url) throws FileNotFoundException, IOException {
       File file = new File(url);
       InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();
        byte[] bytes;
        if (length > Integer.MAX_VALUE) {
            jStatusBar1.setMessage("Plik za duży!");
            bytes = new byte[0];
            return bytes;
        }

        // Create the byte array to hold the data
        bytes = new byte[(int)length];

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Błąd podczas przetwarzania pliku "+file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }

    private void OpenFormImage(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenFormImage
        JFileChooser chooser = new JFileChooser();
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.addChoosableFileFilter(new ImageFilter());
        ImagePreviewPanel preview = new ImagePreviewPanel();
        chooser.setAccessory(preview);
        chooser.addPropertyChangeListener(preview);
        int returnVal = chooser.showOpenDialog(this);
        if (returnVal == 0) {
            String url = chooser.getSelectedFile().getPath();
            System.out.println(url);
            try {
                ImageToBase64(url);
            } catch (FileNotFoundException ex) {
                jStatusBar1.setMessage("Pliku nie znaleziono!");
            } catch (IOException ex) {
                jStatusBar1.setMessage("Błąd podczas otwierania pliku!");
            }
            try{
             encodedImage = "^img^" + encodedImage;
             bs.send(encodedImage);
            } catch (Exception e){
                jStatusBar1.setMessage("Wysylanie nie powiodlo sie...");
            }
            imageOutcoming(url);
        }

    //String imagePath = preview.getFilePatch();
    }//GEN-LAST:event_OpenFormImage

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Przycisk wysylajacy text //
        String out = jTextArea1.getText();
        rozmowaOutcoming(out);
        out = "^txt^" + out;
        bs.send(out);
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    private void initMyComponnents() {
        jStatusBar1 = new JStatusBar();
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());
        contentPane.add(jStatusBar1, BorderLayout.SOUTH);
        jStatusBar1.setMessage("Dziala :)");
        jStatusBar1.setIcon(JStatusBar.TYP_WAIT);
        jButton2.setIcon(MetalIconFactory.getTreeFolderIcon());
    }

    private void initLista() {
        icons = new HashMap<Object, Icon>();
        //icons.put("details", MetalIconFactory.getFileChooserDetailViewIcon());
        //icons.put("folder", MetalIconFactory.getTreeFolderIcon());
        //icons.put("computer", MetalIconFactory.getTreeComputerIcon());

        model = new DefaultListModel();

    // Initialize the list with items
    //String[] items = {"details", "folder", "computer", "computer"};
    //for (int i = 0; i < items.length; i++) {
    //    model.add(i, items[i]);
    //}


    // create a cell renderer to add the appropriate icon
    }

    public void setItemAsClient(String client) {
        for (int i = 0; i < model.size(); i++) {
            String m = (String) model.getElementAt(i);
            if (m.equals(client)) {
                icons.remove(m);
                icons.put(m, MetalIconFactory.getTreeComputerIcon());
                jList1.repaint();
            }

        }

    }

    public void addToList(String nazwa, int ikona) {
        switch (ikona) {
            case 0:
                icons.put(nazwa, MetalIconFactory.getTreeLeafIcon());
                break;
            case 1:
                icons.put(nazwa, MetalIconFactory.getCheckBoxIcon());
                break;
        }

        model.add(model.getSize(), nazwa);
        jList1.setModel(model);
    }

    public void removeFromList(int index) {
        model.remove(index);
        jList1.setModel(model);
    }

    public void clearList() {
        model.removeAllElements();
        jList1.setModel(model);
    }

    public void setStatusBarText(String txt) {
        jStatusBar1.setText(txt);
    }

    public int[] getSelected() {
        boolean anySelected = !jList1.isSelectionEmpty();
        int[] selectedIx;
        if (anySelected == true) {
            selectedIx = jList1.getSelectedIndices();
            return selectedIx;
        }
        selectedIx = new int[1];
        selectedIx[0] = -1;
        return selectedIx;
    }

    public void rozmowaIncoming(String nadawca, String Tresc) {
        rozmowa += "<font color=\"blue\"><b>" + nadawca + ":</b> " + Tresc + "</font><br>";
        jEditorPane1.setText(rozmowa);
    }

    public void rozmowaOutcoming(String Tresc) {
        String nadawca = "Ja";
        rozmowa += "<font color=\"green\"><b>" + nadawca + ":</b> " + Tresc + "</font><br>";
        jEditorPane1.setText(rozmowa);
    }
    
    public void imageOutcoming(String filepatch){
        String nadawca = "Ja";
        rozmowa += "<font color=\"green\"><b>" + nadawca + ":</b></font> <img src =\"file:\\" + filepatch + "/\"><br>";
        jEditorPane1.setText(rozmowa);    
    }

    public void downloadFile(final String filePath) {
        Thread t = new Thread() {

            @Override
            public void run() {
                InputStream is = null;
                try {
                    // iconLabel.setIcon(downloadIcon);
                    String path = filePath;
                    String inputFileName;
                    File file = new File(filePath);
                    if (file.exists()) {
                        is = new FileInputStream(file);
                        inputFileName = file.getName();
                    } else {
                        URL url = new URL(path);
                        is = url.openConnection().getInputStream();
                        inputFileName = url.getFile();
                    }
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[0xFF];
                    int i = is.read(buffer);
                    int done = 0;
                    while (i != -1) {
                        bos.write(buffer, 0, i);
                        done += i;
                        // setProgressValue(done);
                        i = is.read(buffer);
                    }
                    data = bos.toByteArray();
                    fileName = simpleFileName(inputFileName);
                    jStatusBar1.setMessage((data.length / 1024) + "k " + fileName);
                } catch (Throwable e) {
                    //   Logger.error(e);
                    jStatusBar1.setMessage("Download error " + e.getMessage());
                } finally {
                    IOUtils.closeQuietly(is);
                    jStatusBar1.setIcon(btIcon);
                }
            }
        };
        t.start();

    }

    private static String simpleFileName(String filePath) {
        int idx = filePath.lastIndexOf('/');
        if (idx == -1) {
            idx = filePath.lastIndexOf('\\');
        }
        if (idx == -1) {
            return filePath;
        }
        return filePath.substring(idx + 1);
    }

    public void obexPrepare(String adres, String name) {
        String obexUrl = f.findOBEX(adres);
        addDevice(adres, name, obexUrl);
    }

    private void obexSend() {

        if (fileName == null) {
            jStatusBar1.setMessage("No file selected");
            return;
        }
        final DeviceInfo d = InstallDevice;
        if (d == null) {
            jStatusBar1.setMessage("No Device selected");
            return;
        }
        final ObexBluetoothClient o = new ObexBluetoothClient(this, fileName, data);
        Thread t = new Thread() {

            @Override
            public void run() {
                jButton6.setEnabled(false);
                //iconLabel.setIcon(transferIcon);
                String obexUrl = d.obexUrl;
                /*if (!d.obexServiceFound) {
                obexUrl = blueSoleilFindOBEX(d.btAddress, obexUrl);
                }*/
                if (obexUrl != null) {
                    if (o.obexPut(obexUrl)) {
                        selectNextFile();
                    }
                } else {
                    jStatusBar1.setMessage("Service not found");
                }
                jButton6.setEnabled(true);
            //iconLabel.setIcon(btIcon);
            //saveConfig();
            }
        };
        t.start();
    }

    private void selectNextFile() {
        if (queue.size() > 0) {
            String url = (String) queue.remove(0);
            downloadFile(url);
        }
    }

    public void queueFile(String url) {
        queue.add(url);
    }

    public void addDevice(String btAddress, String name, String obexUrl) {
        String key = btAddress.toLowerCase();
        DeviceInfo di = new DeviceInfo();
        //    if (di == null) {
        //            di = new DeviceInfo();
        //    }
        di.btAddress = btAddress;
        // Update name if one found
        di.name = name;
        di.obexUrl = obexUrl;
        di.obexServiceFound = true;
        // devices.put(key, di);
        InstallDevice = di;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JEditorPane jEditorPane1;
    private javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
    private JFileChooser fileChooser;
    private byte[] data;
    public JStatusBar jStatusBar1 = new JStatusBar();
    private DefaultListModel model;
    Map<Object, Icon> icons;
    String rozmowa = new String();
    // obiekty zwizane z BlueTooth //
    Finder f;
    Connector c;

    public void showStatus(String message) {
        jStatusBar1.setMessage(message);
    }

    public void setProgressMaximum(int n) {
        jProgressBar1.setMaximum(n);
    }

    public void setProgressValue(int n) {
        jProgressBar1.setValue(n);
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                jProgressBar1.setString(status);
            }
        });

    }

    public void setProgressDone() {
        jProgressBar1.setValue(0);
    }
}
